/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.cesupa.sessionbean;

import br.cesupa.localinterface.GenericDAO;
import java.lang.reflect.ParameterizedType;
import java.util.List;

/**
 *
 * @author koiti
 */
public class GenericSUDI<T> extends ObjectSUDI implements GenericDAO<T> {

    private Class<T> entityBeanType;

    public GenericSUDI(){
        this.entityBeanType = (Class<T>) ((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];
    }

    public void salvar(T instance) {
        super.save(instance);
    }

    public T atualizar(T instance) {
        return (T) super.update(instance);
    }

    public void remover(T instance) {
        super.remove(instance);
    }

    public T getById(Long id) {
        return (T) super.executeNamedQueryObject(entityBeanType.getSimpleName()+".findById", "id", id);
    }

    public List<T> getAll() {
        return super.executeNamedQueryList(entityBeanType.getClass().getSimpleName()+".findAll");
    }
}
